﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BeerScanatronServer
{
    public class ListBoxListener : TraceListener
    {
        private ListBox _listBox;

        public ListBoxListener(ListBox listbox)
        {
            _listBox = listbox;
        }

        public override void Write(string message)
        {
            this.WriteLine(message);
        }

        public override void WriteLine(string message)
        {
            if (_listBox.Items.Count > 1000)
            {
                _listBox.Items.RemoveAt(0);
            }

            _listBox.Items.Add(message);
            _listBox.TopIndex = _listBox.Items.Count - 1;
        }
    }
}